﻿@{
    ViewBag.Title = "寄售库盘点单据信息";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var autoSearch = true;
    var number = '@ViewBag.number';
    $(function () {
        initControl();
        gridList();
        $('#FProductionNO').on("change", function () {
            if (autoSearch) {
                $('#FProductionNO1').val($('#FProductionNO').val());
                $('#FProductionNO1').focus();
                $('#btn_search').click();
            } else {
                autoSearch = true;
            }
        });
    });
    function initControl() {
        var FDocuNO = $.request("FDocuNO");
        if (!!FDocuNO) {
            $('#FDocuNO').val(FDocuNO);
        }
        var FDocuNOShow = $.request("FDocuNOShow");
        if (!!FDocuNOShow) {
            $('#FDocuNOShow').val(FDocuNOShow);
        }
        var FHappenComNO = $.request("FHappenComNO");
        if (!!FHappenComNO) {
            $('#FHappenComNO').val(FHappenComNO);
        }
        var FDescription = $.request("FDescription");
        if (!!FDescription) {
            $('#FDescription').val(FDescription);
        }
        var FDocuTypeNO = $.request("FDocuTypeNO");
        if (!!FDocuTypeNO) {
            $('#FDocuTypeNO').val(FDocuTypeNO);
        }
        var FCurDate = $.request("FCurDate");
        if (!!FCurDate) {
            $('#FCurDate').val(FCurDate);
        }
        var FCredence = $.request("FCredence");
        if (!!FCredence) {
            $('#FCredence').val(FCredence);
        }
        if (FDocuNO != '') {
            lockInputById("#item");
        }
        initBindSelect("#form1");

        //零件编号 
        $("#FProductionNO").bindSelect({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStorKW/SelectPartForDropList",
            id: "FProductionNO",
            text: "FProductionNO",
            search: true
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/WareHouse/Consignment/GetConsignmentSelectProductionJson",
            postData: { FProductionNO: $("#FProductionNO1").val() },
            height: 240,
            colModel: [
            { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 180, align: 'left' },
            { label: '单价(元)', name: 'Fprice', width: 120, align: 'left' },
            { label: '零件分类编码', name: 'FProductionTypeNO', width: 120, align: 'left' },
            { label: '零件分类名称', name: 'FProductionTypeName', width: 180, align: 'left' },
            ],
            pager: "#gridPager",
            sortname: 'FProductionNO desc',
            rownumWidth: 40,
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                autoSearch = false;
                $("#detail").formSerialize(rowData, "");
                $("#FProductionType").val(rowData.FProductionTypeNO + ' ' + rowData.FProductionTypeName);
            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                }
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { FProductionNO: $("#FProductionNO1").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_ok() {
        if (!$('#form1').formValid()) {

        } else {
            var param = $("#item").formSerialize();
            param["detail"] = JSON.stringify($("#detail").formSerialize());
            $.submitForm({
                url: "/WareHouse/Consignment/SubmitConsignmentShelvesForm?status=I",
                param: param,
                close: false,
                success: function (result) {
                    setDataByJson('#item', result.data);
                    if ($('#FDocuNO').val() != '') {
                        $('#FDocuNOShow').val($('#FDocuNO').val());
                    }
                    lockInputById("#item");
                    $('#FDescription').prop("disabled", false);
                    emptyDataById("#detail");
                    initBindSelect("#detail");
                    var father = $.currentSubSubWindow().frames["Detail"];
                    father.reloadPageData($("#item").formSerialize());
                }
            })
        }
    }
    function btn_cancel() {
        var father = $.currentSubSubWindow().frames["Detail"];
        father.$.detailCloseTop();
    }
    
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div style="padding-top: 1px;margin-left:10px;margin-right:10px;">
        <form id="form1">
            <table id="item" class="form" style="margin:10px 0;">
                <tr>
                    <th class="formTitle" style="width:60px;">盘点单位</th>
                    <td class="formValue" style="width:220px;">
                        <select id="FHappenComNO" name="FHappenComNO" class="form-control required">
                            <option value="">&nbsp;</option>
                            @foreach (var item in ViewBag.fhappencomList)
                            {
                                <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                            }
                        </select>
                    </td>
                    <th class="formTitle" style="width:60px;">摘要说明</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FDescription" name="FDescription" type="text" class="form-control" />
                    </td>
                    <th class="formTitle" style="width:60px;">单据编号</th>
                    <td class="formValue">
                        <input id="FDocuNOShow" name="FDocuNOShow" type="text" class="form-control" disabled="disabled" value="" />
                        <input id="FDocuNO" name="FDocuNO" type="hidden" value="">
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">发生方式</th>
                    <td class="formValue">
                        <select id="FDocuTypeNO" name="FDocuTypeNO" class="form-control required">
                            @foreach (var item in ViewBag.fdocutypenoList)
                            {
                                <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                            }
                        </select>
                    </td>
                    <th class="formTitle">单据日期</th>
                    <td class="formValue">
                        <input id="FCurDate" name="FCurDate" type="text" class="form-control input-wdatepicker required" onfocus="WdatePicker()" />
                    </td>
                    <th class="formTitle">凭证编号</th>
                    <td class="formValue">
                        <input id="FCredence" name="FCredence" type="text" class="form-control required" value="" />
                    </td>
                </tr>
            </table>
            <hr style="margin-top:10px;margin-bottom:10px;" />
            <table id="detail" class="form" style="border:1px solid #ddd;">
                <tr>
                    <th class="formTitle" style="width:60px;">零件编号</th>
                    <td class="formValue" style="width:220px;">
                        <select id="FProductionNO" name="FProductionNO" class="form-control required">
                            @*<option value="">&nbsp;</option>
                            @foreach (var item in ViewBag.fproductionList)
                            {
                                <option value="@item.FProductionNO">@item.FProductionNO</option>
                            }*@
                        </select>
                    </td>
                    <th class="formTitle" style="width:60px;">零件名称</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FProductionName" name="FProductionName" type="text" readonly="readonly" class="form-control " />
                    </td>
                    <th class="formTitle" style="width:60px;">零件分类</th>
                    <td class="formValue">
                        <input id="FProductionType" name="FProductionType" type="text" readonly="readonly" class="form-control " />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">仓库编号</th>
                    <td class="formValue" style="width:160px;">
                        <select id="FStoreNO" name="FStoreNO" class="form-control required">
                            <option value="">&nbsp;</option>
                            @foreach (var item in ViewBag.fstoreList)
                        {
                                <option value="@item.FStoreNO">@item.FStoreNO @item.FStoreName</option>
                        }
                        </select>
                    </td>
                    <th class="formTitle" style="width:100px;">开票数量</th>
                    <td class="formValue">
                        <input id="FQuantity" name="FQuantity" type="text" class="form-control text-right required digits" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">件</label>
                    </td>
                    <th class="formTitle" style="width:100px;">零件单价</th>
                    <td class="formValue">
                        <input id="FPrice" name="FPrice" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">元</label>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">备注</th>
                    <td class="formValue" colspan="5">
                        <input name="FDescription" type="text" class="form-control" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <hr style="margin-top:10px;margin-bottom:0px;" />
    <div style="margin-left: 10px; margin-right: 10px;border-bottom:1px solid #ccc;">
        <table class="form">
            <tr>
                <th class="formTitle" style="width:60px;">零部件号</th>
                <td class="formValue" style="width:140px;">
                    <input id="FProductionNO1" class="form-control " type="text">
                </td>
                <td class="formValue">
                    <div class="btn-group" style="margin-left:10px;margin-top:3px;">
                        <a id="btn_search" class="btn btn-primary center-block btn-1 " onclick="btn_search();"><span class="glyphicon glyphicon-search"></span> 查询</a>
                    </div>
                </td>
            </tr>
        </table>
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <div style="text-align:right;margin-left: 10px; margin-right: 10px;padding:5px 40px;">
        <div class="btn-group" style="">
            <a id="btn_ok" class="btn btn-primary center-block" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确定</a>
        </div>
        <div class="btn-group" style="margin-left:30px;">
            <a id="btn_cancel" class="btn btn-danger center-block" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 关闭</a>
        </div>
    </div>
</div>